package main

/*
排序并且获取指定目标的排序位置
userid = ussgfttqqq559gjkkkkkr4
db.getCollection('BloodGlucose').aggregate([
    {"$sort":{"is_manual_input":-1,"date":-1}}, //按照分数排序
    {"$group":{"_id":"null","all":{"$push":"$userid"}}},  // 将所有排序结果push到all数组中，方便下面使用$indexOfArray
    {"$project":{"_id":0,"total":{"$size":"$all"},"index":{"$indexOfArray":[ "$all","ussgfttqqq559gjkkkkkr4"] }}}  // 这里的openid为要查找名次的openid
])
 */

/*
query = []bson.M{
				bson.M{"$match": bson.M{"userid": UserId, "status": 1, "$or": []bson.M{bson.M{"insulin_bolus": bson.M{"$ne": 0.0}}, bson.M{"insulin_basal": bson.M{"$ne": 0.0}}}, "date": bson.M{"$gte": endNum, "$lte": startNum}}},
				bson.M{"$group": bson.M{"_id": "$date", "sum_insulin_bolus": bson.M{"$sum": "$insulin_bolus"}, "sum_insulin_basal": bson.M{"$sum": "$insulin_basal"}, "z_time": bson.M{"$first": "$z_time"}}},
				bson.M{"$sort": bson.M{"_id": -1}},
			}
			resList := collActor.Pipe(query).All(&AllData)
 */


/*
mongo创建文本搜索
db.getCollection('Chat').createIndex(
   {content : "text" ,
   title   : "text" ,},
   {default_language: "none"}
)
 */

/*
分组并且把每组的数据全部列出来
db.getCollection('BloodGlucose').aggregate([
    {"$project":{"_id":1,"userid":1,"status":1}},
    {"$sort":{"is_manual_input":-1,"date":-1}},
    {"$group":{"_id":"$userid","doc":{"$push":"$$ROOT"}}},
])
 */

/*
获取分组及其组数
db.getCollection('BloodGlucose').aggregate([{
"$group": {_id: "$userid", count: {"$sum": 1}}
}
])
 */